// const api = require("../../../demos/pages/merchant/api")
import api from '../../../utils/api.js';//这个里面封装了request方法
const app = getApp();
const HALL = require('../index') 
// pages/purchaseHall/purchaseList/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //未
    listType: 1, // 1为1个商品一行，2为2个商品一行    
    name: '', // 搜索关键词
    orderBy: '', // 排序规则
    page: 1 ,// 读取第几页
    // isMyFabu:false；
    myId:app.globalData.userId,//app.globalData.userId,

    //XP
    forms:[
      // {
      //     "formId": "1",
      //     "userId": "1",
      //     "catId": "1",
      //     "itemId": "1",
      //     "cycle": "day",
      //     "count": 2000,
      //     "receiptAddress": "湖南",
      //     "expectedAddress": "河北",
      //     "price": 2.0,
      //     "description": null,
      //     "offercount": 1,
      //     "status": 0,
      //     "units": "斤",
      //     "ddl": "2021-07-15",
      //     "totalcount": 2000,
      //     "itemName": "西瓜",
      //     "categoryId": "1",
      //     "image1": "https://dcdn.it120.cc/2021/07/15/b1763660-78bd-4a2d-bbae-9e68dc76bdbc.png",
      //     "image2": null
      // },
      // {
      //     "formId": "2",
      //     "userId": "2",
      //     "catId": "5",
      //     "itemId": "10",
      //     "cycle": "month",
      //     "count": 7700,
      //     "receiptAddress": "云南",
      //     "expectedAddress": "四川",
      //     "price": 1.0,
      //     "description": null,
      //     "offercount": 3,
      //     "status": 0,
      //     "units": "个",
      //     "ddl": "2021-07-15",
      //     "totalcount": 8000,
      //     "itemName": "鸡蛋",
      //     "categoryId": "5",
      //     "image1": "https://dcdn.it120.cc/2021/07/15/f0a26c05-afee-4ea7-a410-d9cdee090a7d.png",
      //     "image2": null
      // }
  ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("onLoad 小");
    this.getALLForms();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log("onready")
    this.getALLForms();

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("onshow")
    this.getALLForms();
    

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.getALLForms();

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log("onUnload")
    this.getALLForms();

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("下拉刷新")
    this.getALLForms();;

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getALLForms();

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    this.getALLForms();

  },
  test(){
    this.getALLForms();
  },
  getALLForms(){
    // 首页pic 
    console.log('getUserInfoById');
    const url = 'forms/users/'+app.globalData.userId+'/filter';
    console.log("getALLForms")
     api.get(url).then(res => {

      //得到的数据
      // let { code, data, msg } = res;
      console.log(res)
      this.setData({forms:res.data});
      var num = this.data.forms.length;
      // app.globalData.purchaseTips = num
      // app.setData({['globalData.purchaseTips']:num})
      // console.log(app.globalData.purchaseTips)
     
      // HALL.setData({['globalData.purchaseTips']:num})
      console.log(this.data.myId);
      console.log(this.data.forms);
    }).catch(err => {
      console.log(err)
      wx.showToast({
        title: "请求错误",
        icon: 'none'
      })
    })
  }
})